

let page = document.getElementById('buttonDiv');
const kButtonColors = ['#3aa757', '#e8453c', '#f9bb2d', '#4688f1'];
function constructOptions(kButtonColors) {
  for (let item of kButtonColors) {
    let button = document.createElement('button');
    button.style.backgroundColor = item;
    button.addEventListener('click', function () {
      chrome.storage.sync.set({ color: item }, function () {
        console.log('color is ' + item);
      })
    });
    page.appendChild(button);
  }
}
constructOptions(kButtonColors);

let domInputGitlabUrl: any = document.getElementById('iptGitlabUrl');
let domInputGitlabToken: any = document.getElementById('iptGitlabToken');
let domInputRap2Url: any = document.getElementById('iptRap2Url');

document.getElementById('btnSaveConfig').onclick = e => {
  chrome.storage.sync.set({
    gitlabConfig: {
      gitlabUrl: domInputGitlabUrl.value,
      gitlabToken: domInputGitlabToken.value,
      rap2Url: domInputRap2Url.value
    }
  }, () => {
  });
};

function loadConfig() {
  chrome.storage.sync.get('gitlabConfig', function (config) {
    let data = config.gitlabConfig || {};
    domInputGitlabUrl.value = data.gitlabUrl || '';
    domInputGitlabToken.value = data.gitlabToken || '';
    domInputRap2Url.value = data.rap2Url || '';
  });
}

loadConfig();

